From c54c6a9df4ddb7d8509af09f687faba9efe73af9 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 6 May 2015 19:29:05 -0700 Subject: [PATCH] Add a Kind argument to target_filenames Knowing the target architecture for calculating the filename is needed when calculating the name of a dynamic library, and previously this was only taken into account when a target was a plugin. Targets can, however, request that they are built as a dynamic library which also needs to be taken into account. Closes #1589 --- src/cargo/ops/cargo_clean.rs | 5 +++-- src/cargo/ops/cargo_rustc/context.rs | 5 ++--- src/cargo/ops/cargo_rustc/fingerprint.rs | 7 ++++--- src/cargo/ops/cargo_rustc/mod.rs | 21 ++++++++++++--------- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/cargo/ops/cargo_clean.rs b/src/cargo/ops/cargo_clean.rs index 585426cf3..cbeb3e61b 100644 --- a/src/cargo/ops/cargo_clean.rs +++ b/src/cargo/ops/cargo_clean.rs @@ -7,7 +7,7 @@ use core::{PackageSet, Profiles, Profile}; use core::source::{Source, SourceMap}; use sources::PathSource; use util::{CargoResult, human, ChainError, Config}; -use ops::{self, Layout, Context, BuildConfig}; +use ops::{self, Layout, Context, BuildConfig, Kind}; pub struct CleanOptions<'a, 'b: 'a> { pub spec: Option<&'a str>, @@ -63,7 +63,8 @@ pub fn clean(manifest_path: &Path, opts: &CleanOptions) -> CargoResult<()> { try!(rm_rf(&layout.fingerprint(&pkg))); let profiles = [Profile::default_dev(), Profile::default_test()]; for profile in profiles.iter() { - for filename in try!(cx.target_filenames(&pkg, target, profile)).iter() { + for filename in try!(cx.target_filenames(&pkg, target, profile, + Kind::Target)).iter() { try!(rm_rf(&layout.dest().join(&filename))); try!(rm_rf(&layout.deps().join(&filename))); } diff --git a/src/cargo/ops/cargo_rustc/context.rs b/src/cargo/ops/cargo_rustc/context.rs index 9cfa05a17..cb52e9446 100644 --- a/src/cargo/ops/cargo_rustc/context.rs +++ b/src/cargo/ops/cargo_rustc/context.rs @@ -299,7 +299,8 @@ impl<'a, 'b: 'a> Context<'a, 'b> { /// Return the filenames that the given target for the given profile will /// generate. pub fn target_filenames(&self, pkg: &Package, target: &Target, - profile: &Profile) -> CargoResult> { + profile: &Profile, kind: Kind) + -> CargoResult> { let stem = self.file_stem(pkg, target, profile); let suffix = if target.for_host() {&self.host_exe} else {&self.target_exe}; @@ -316,8 +317,6 @@ impl<'a, 'b: 'a> Context<'a, 'b> { for lib in libs.iter() { match *lib { LibKind::Dylib => { - let plugin = target.for_host(); - let kind = if plugin {Kind::Host} else {Kind::Target}; let (prefix, suffix) = try!(self.dylib(kind)); ret.push(format!("{}{}{}", prefix, stem, suffix)); } diff --git a/src/cargo/ops/cargo_rustc/fingerprint.rs b/src/cargo/ops/cargo_rustc/fingerprint.rs index 707f0ccb9..0b1ac8aa1 100644 --- a/src/cargo/ops/cargo_rustc/fingerprint.rs +++ b/src/cargo/ops/cargo_rustc/fingerprint.rs @@ -51,13 +51,14 @@ pub fn prepare_target<'a, 'b>(cx: &mut Context<'a, 'b>, info!("fingerprint at: {}", loc.display()); - let fingerprint = try!(calculate(cx, pkg, target, profile, kind)); - let is_fresh = try!(is_fresh(&loc, &fingerprint)); + let mut fingerprint = try!(calculate(cx, pkg, target, profile, kind)); + let is_fresh = try!(is_fresh(&loc, &mut fingerprint)); let root = cx.out_dir(pkg, kind, target); let mut missing_outputs = false; if !profile.doc { - for filename in try!(cx.target_filenames(pkg, target, profile)).iter() { + for filename in try!(cx.target_filenames(pkg, target, profile, + kind)).iter() { missing_outputs |= fs::metadata(root.join(filename)).is_err(); } } diff --git a/src/cargo/ops/cargo_rustc/mod.rs b/src/cargo/ops/cargo_rustc/mod.rs index e1535bb8f..21177e965 100644 --- a/src/cargo/ops/cargo_rustc/mod.rs +++ b/src/cargo/ops/cargo_rustc/mod.rs @@ -133,8 +133,10 @@ pub fn compile_targets<'a, 'b>(targets: &[(&'a Target, &'a Profile)], cx.compilation.extra_env.insert("OUT_DIR".to_string(), out_dir); for &(target, profile) in targets { - for filename in try!(cx.target_filenames(pkg, target, profile)).iter() { - let dst = cx.out_dir(pkg, Kind::Target, target).join(filename); + let kind = Kind::Target; + for filename in try!(cx.target_filenames(pkg, target, profile, + kind)).iter() { + let dst = cx.out_dir(pkg, kind, target).join(filename); if profile.test { cx.compilation.tests.push((target.name().to_string(), dst)); } else if target.is_bin() || target.is_example() { @@ -154,10 +156,9 @@ pub fn compile_targets<'a, 'b>(targets: &[(&'a Target, &'a Profile)], if profile.doc { continue } if cx.compilation.libraries.contains_key(&pkgid) { continue } - let v = try!(cx.target_filenames(pkg, target, profile)); + let v = try!(cx.target_filenames(pkg, target, profile, kind)); let v = v.into_iter().map(|f| { - (target.clone(), - cx.out_dir(pkg, Kind::Target, target).join(f)) + (target.clone(), cx.out_dir(pkg, kind, target).join(f)) }).collect::>(); cx.compilation.libraries.insert(pkgid.clone(), v); } @@ -342,7 +343,8 @@ fn rustc(package: &Package, target: &Target, profile: &Profile, } let exec_engine = cx.exec_engine.clone(); - let filenames = try!(cx.target_filenames(package, target, profile)); + let filenames = try!(cx.target_filenames(package, target, profile, + kind)); let root = cx.out_dir(package, kind, target); // Prepare the native lib state (extra -L and -l flags) @@ -753,13 +755,14 @@ fn build_deps_args(cmd: &mut CommandPrototype, // If this target is itself a plugin *or* if it's being linked to a // plugin, then we want the plugin directory. Otherwise we want the // target directory (hence the || here). - let layout = cx.layout(pkg, match kind { + let kind = match kind { Kind::Host => Kind::Host, Kind::Target if target.for_host() => Kind::Host, Kind::Target => Kind::Target, - }); + }; + let layout = cx.layout(pkg, kind); - for filename in try!(cx.target_filenames(pkg, target, profile)).iter() { + for filename in try!(cx.target_filenames(pkg, target, profile, kind)).iter() { if filename.ends_with(".a") { continue } let mut v = OsString::new(); v.push(&target.crate_name()); -- 2.30.2